package com.xyy.ec.pop.api.kingdinggmp.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@Aspect
public class TaskTimeAspect {
    @Around("@annotation(org.springframework.scheduling.annotation.Scheduled)")
    public Object taskTime(@NotNull ProceedingJoinPoint joinPoint) throws Throwable {
        //获取方法名
        String methodName = joinPoint.getSignature().toShortString();
        long begin = System.currentTimeMillis();
        Object proceed = joinPoint.proceed();
        long end = System.currentTimeMillis();
        //计算执行时间
        long executionTime = end - begin;
        log.info("当前方法 {}  总耗时: {} ms", methodName, executionTime);
        return proceed;
    }
}
